import java.util.Scanner;

public class Test1 {
    public static void login(String name, String password) {
        Scanner input = new Scanner(System.in);
        for (int i = 1; i <= 3; i++) {
            System.out.println("请输入账号:");
            String logname = input.next();
            System.out.println("请输入密码:");
            String logpassword = input.next();
            if (logname.equals(name) && logpassword.equals(password)) {
                System.out.println("登陆成功");
                break;
            } else if (i < 3) {
                System.out.println("账号或密码错误,请重新输入,您还有" + (3 - i) + "次机会");
            } else {
                System.out.println("账号或密码错误3次,吞卡,请找工作人员处理");
                System.exit(0);
            }
        }

    }

    public static int face() {
        Scanner input = new Scanner(System.in);
        System.out.println("1.查询余额, 2.存款, 3.取款, 4.修改密码, 5.退出");
        System.out.println("请输入要进行的操作序号:");
        int choice = input.nextInt();
        return choice;
    }

    public static void iscontinue() {
        Scanner input = new Scanner(System.in);
        boolean cont = false;
        do {
            System.out.println("是否继续操作y/n");
            String answer = input.next();
            if (answer.equals("y")) {
                break;
            } else if (answer.equals("n")) {
                System.out.println("退出成功");
                System.exit(0);
            } else {
                System.out.println("非法字符,请重新输入");
                cont = true;
            }
        } while (cont);
    }

    public static void select(double[] money) {
        System.out.println("您的余额为:" + money[0] + "元");
        iscontinue();
    }

    public static void save(double[] money) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入您要存款的金额:");
        double saving = input.nextDouble();
        if (saving > 10000) {
            System.out.println("单次存款金额不得超过1万元");
            iscontinue();
        } else if (saving <= 0) {
            System.out.println("输入金额错误");
            iscontinue();
        } else if (saving % 100 != 0) {
            System.out.println("请输入100的倍数存款");
            iscontinue();
        } else {
            money[0] += saving;
            System.out.println("您的余额为:" + money[0] + "元");
            iscontinue();
        }
    }

    public static void take(double[] money) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入您要取款的金额:");
        double taking = input.nextDouble();
        if (taking > money[0]) {
            System.out.println("余额不足");
            iscontinue();
        } else if (taking <= 0) {
            System.out.println("输入金额错误");
            iscontinue();
        } else if (taking > 3000) {
            System.out.println("单次取款金额不得超过3千元");
            iscontinue();
        } else if (taking % 100 != 0) {
            System.out.println("请输入100的倍数取款");
            iscontinue();
        } else {
            money[0] -= taking;
            System.out.println("您的余额为:" + money[0] + "元");
            iscontinue();
        }
    }

    public static void changepassword(String password) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入旧密码:");
        String oldpassword = input.next();
        if (oldpassword.equals(password)) {
            System.out.println("请输入新密码:");
            String newpassword1 = input.next();
            System.out.println("请再次输入新密码:");
            String newpassword2 = input.next();
            if (newpassword1.equals(newpassword2)) {
                System.out.println("密码修改成功");
                System.out.println("当前密码为:" + newpassword1);
                iscontinue();
            } else {
                System.out.println("两次输入的密码不一致");
                System.out.println("当前密码为:" + password);
                iscontinue();
            }
        } else {
            System.out.println("密码输入错误");
            System.out.println("当前密码为:" + password);
            iscontinue();
        }

    }

    public static void main(String[] args) {
        System.out.println("----------------------------");
        System.out.println("******   欢迎登录   ******");
        System.out.println("*****   中国人民银行   *****");
        System.out.println("******   版本1.0   ******");
        System.out.println("----------------------------");
        String name = "admin";
        String password = "123";
        login(name, password);
        double[] money = {10000};
        while (true) {
            int choice = face();
            switch (choice) {
                case 1:
                    select(money);
                    break;
                case 2:
                    save(money);
                    break;
                case 3:
                    take(money);
                    break;
                case 4:
                    changepassword(password);
                    break;
                case 5:
                    System.out.println("退出成功");
                    System.exit(0);
                    break;
                default:
                    System.out.println("非法字符,请重新输入");
                    break;
            }
        }
    }
}
